package org.gnyxy.controller.background;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.gnyxy.dto.AddressDicPageQueryDTO;
import org.gnyxy.entity.AddressDic;
import org.gnyxy.result.PageResult;
import org.gnyxy.result.Result;
import org.gnyxy.service.AddressDicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminAddressDicController")
@RequestMapping("/background/addressDic")
@Slf4j
@Api(tags = "商家后台-地址字典管理")
public class AddressDicController {
    @Autowired
    private AddressDicService addressDicService;

    @PostMapping("/add")
    @ApiOperation("添加地址")
    public Result add(@RequestBody AddressDic addressDic){
        log.info("添加地址: {}",addressDic);
        addressDicService.add(addressDic);
        return Result.success();
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除地址")
    public Result deleteById(@PathVariable Long id){
        log.info("删除地址,id: {}",id);
        addressDicService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询地址")
    public Result<AddressDic> getById(@PathVariable Long id){
        log.info("根据id: {} ,查询地址",id);
        AddressDic addressDic = addressDicService.getById(id);
        return Result.success(addressDic);
    }

    @PostMapping("/update")
    @ApiOperation("更新地址")
    public Result update(@RequestBody AddressDic addressDic){
        log.info("更新地址: {}",addressDic);
        addressDicService.update(addressDic);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(AddressDicPageQueryDTO addressDicPageQueryDTO){
        log.info("分页查询: {}",addressDicPageQueryDTO);
        PageResult result = addressDicService.page(addressDicPageQueryDTO);
        return Result.success(result);
    }

}
